home *** CD-ROM | disk | FTP | other *** search
- (*
- ================================================================================
- Animated TrayIcon VCL Demo
- ================================================================================
- Credits:
- This demo makes use of the source code for the freeware "URL Label" component
- by Ahto Tanner. While the component is not being used directly, it's source
- is being used to create the URL for our home page that appears on the last
- screen of this demo. Thanks Ahto for the good work.
-
- For more information on the "URL Label" component:
- URL Label
- Freeware - created by Ahto Tanner (www.estpak.ee/~ahto)
- Special thanks to Chad Z. Hower from Phoenix Business Enterprises
-
- Notes:
- For those who are interested, navigation in this demo occurs between pages
- and between steps in a page. Step navigation generally speaking relates
- to the hiding and showing of bullets, and page navigation relates to
- displaying a high level feature of the Animated TrayIcon VCL.
- ================================================================================
- *)
- unit Main;
-
- interface
-
- uses
- WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, StdCtrls, Buttons, Menus, ShellApi, ClipBrd, PGTray95;
-
- type
- TMainForm = class(TForm)
- Panel1: TPanel;
- Panel: TPanel;
- Panel3: TPanel;
- Pages: TNotebook;
- CurrentPage: TPanel;
- Label1: TLabel;
- Page1Label1: TLabel;
- Panel2: TPanel;
- StatusBar: TPanel;
- Panel4: TPanel;
- NextButton: TButton;
- BackButton: TButton;
- Page2Label1: TLabel;
- Page1Label8: TLabel;
- Button1: TButton;
- Image1: TImage;
- Page2Image1: TImage;
- Page2Bullet: TImage;
- Label2: TLabel;
- Page3Bullet: TImage;
- Label10: TLabel;
- Page3Label: TLabel;
- Image4: TImage;
- Label7: TLabel;
- Image7: TImage;
- Page4Bullet: TImage;
- Label13: TLabel;
- Page4Label1: TLabel;
- Page4Label2: TLabel;
- Page4Label3: TLabel;
- Page5Label3: TLabel;
- Page5Label2: TLabel;
- Page5Label1: TLabel;
- Page5Bullet: TImage;
- Label19: TLabel;
- Image9: TImage;
- Label20: TLabel;
- Page5Label2a: TLabel;
- Page5Label3a: TLabel;
- Page5Label3b: TLabel;
- Page5Label3c: TLabel;
- Page5Label3d: TLabel;
- Page5Label1a: TLabel;
- Page4Label4: TLabel;
- Label14: TLabel;
- Page1Label2: TLabel;
- Page1Label3: TLabel;
- Page1Label4: TLabel;
- Page4Label5a: TLabel;
- Page4Label5b: TLabel;
- Page4Label5c: TLabel;
- URLPopupMenu: TPopupMenu;
- URLCopyMenuItem: TMenuItem;
- Page4Label1b: TLabel;
- Page1Bullet: TImage;
- Page1Label6: TLabel;
- TrayIconPopup: TPopupMenu;
- ShowDemo1: TMenuItem;
- HideDemo1: TMenuItem;
- N1: TMenuItem;
- Registration1: TMenuItem;
- About1: TMenuItem;
- N2: TMenuItem;
- Exit2: TMenuItem;
- TrayIcon: TPGTrayIcon95;
- BrowseForIconDialog: TOpenDialog;
- Page3Label1: TLabel;
- TrackingListBox: TListBox;
- Button2: TButton;
- Label3: TLabel;
- HideIconButton: TButton;
- ShowIconButton: TButton;
- Page2Label4: TLabel;
- Page2Label5: TLabel;
- DisabledIconImage: TImage;
- EnabledIconImage: TImage;
- DisabledLabel: TLabel;
- EnabledLabel: TLabel;
- AnimatedLabel: TLabel;
- Page2Label3: TLabel;
- AnimatedRadioButton: TRadioButton;
- EnabledRadioButton: TRadioButton;
- DisabledRadioButton: TRadioButton;
- Page2Label2: TLabel;
- SamplesComboBox: TComboBox;
- AutoPopupLabel: TLabel;
- ShowHintLabel: TLabel;
- HintLabel: TLabel;
- HintEdit: TEdit;
- ShowHintCheckbox: TCheckBox;
- AutoPopupCheckbox: TCheckBox;
- Page1Label7: TLabel;
- Page4Image1: TImage;
- Page4Image2: TImage;
- Page4Image3: TImage;
- Page1Label5: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure NextButtonClick(Sender: TObject);
- procedure BackButtonClick(Sender: TObject);
- procedure CurrentPageMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure Button1Click(Sender: TObject);
- procedure AbouttheProgrammersGuild1Click(Sender: TObject);
- procedure HowtoRegister1Click(Sender: TObject);
- procedure URLLabelClick(Sender: TObject);
- procedure URLCopyMenuItemClick(Sender: TObject);
- procedure Page4Label5bMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure Page5Label2aMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure Page4Label1bMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure Page4Label1bClick(Sender: TObject);
- procedure ShowIconButtonClick(Sender: TObject);
- procedure HideIconButtonClick(Sender: TObject);
- procedure AnimatedLabelClick(Sender: TObject);
- procedure EnabledLabelClick(Sender: TObject);
- procedure DisabledLabelClick(Sender: TObject);
- procedure AnimatedRadioButtonClick(Sender: TObject);
- procedure EnabledRadioButtonClick(Sender: TObject);
- procedure DisabledRadioButtonClick(Sender: TObject);
- procedure AutoPopupLabelClick(Sender: TObject);
- procedure ShowHintLabelClick(Sender: TObject);
- procedure AutoPopupCheckboxClick(Sender: TObject);
- procedure ShowHintCheckboxClick(Sender: TObject);
- procedure HintEditChange(Sender: TObject);
- procedure TrayIconClick(Sender: TObject);
- procedure TrayIconDblClick(Sender: TObject);
- procedure SamplesComboBoxChange(Sender: TObject);
- procedure EnabledIconImageDblClick(Sender: TObject);
- procedure DisabledIconImageDblClick(Sender: TObject);
- procedure TrayIconMouseEnter(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure TrayIconMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure TrayIconMouseExit(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure Button2Click(Sender: TObject);
- procedure ShowDemo1Click(Sender: TObject);
- procedure HideDemo1Click(Sender: TObject);
- procedure Registration1Click(Sender: TObject);
- procedure About1Click(Sender: TObject);
- procedure Exit2Click(Sender: TObject);
- procedure Page5Label1aClick(Sender: TObject);
- procedure Page5Label1aMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure TrayIconAppMinimize(Sender: TObject);
- procedure FormShow(Sender: TObject);
- private
- GoingForward: Boolean;
- PlayingForward: Boolean;
- CurrStep: Integer;
- public
- { Used to control step navigation. }
- function PrevStep: Integer;
- function NextStep: Integer;
- function FirstStep: Integer;
- function LastStep: Integer;
- procedure DisplayStep(AStep: Integer);
- function NumberOfStepsInPage(APageIndex: Integer): Integer;
- procedure InitNewStep;
- { Used to control page navigation. }
- function GoBackward: Boolean;
- function GoForward: Boolean;
- function FirstPage: Integer;
- function LastPage: Integer;
- function CurrPage: Integer;
- procedure DisplayPage(APageIndex: Integer);
- procedure DisplayNextPage;
- procedure DisplayPrevPage;
- procedure InitEndOfPage(APageIndex: Integer);
- { Routines used to hide and show objects depending on the direction }
- { that we're heading. (ie Depends on whether the user has clicked the }
- { forward or backward button.) }
- procedure ShowObject(AnObjectName: string);
- procedure ShowBullet(AnObjectName: string);
- procedure ShowBulletedLabel(AStep: Integer);
- function PageObject(AnObjectName: string): TControl;
- function StepObject(AnObjectName: string; AStep: Integer): TControl;
- function PageObjectName(AName: string): string;
- { Other routines. }
- procedure ShowMsg(AMsg: string);
- procedure ShowAbout;
- procedure ShowDemoDialog(Sender: TObject);
- procedure ChangeDirectory(APath: string);
- procedure DisplayHintInStatusBar(Sender: TObject);
- procedure UpdateStatusBar(StatusText: string);
- procedure UpdateNavigationState;
- procedure ShowTrackingMessage(AString: string; X,Y: Integer);
- procedure MakeHotSpotLabel(ALabel: TLabel);
- end;
-
- var
- MainForm: TMainForm;
-
- const
- crPGURLHand = 6;
-
- procedure PGAssert(const Condition: Boolean; const Msg: string);
- procedure PGError(const Msg: string);
- function PGMax(X, Y: Integer): Integer;
- function PGMin(X, Y: Integer): Integer;
- function PGCenter(ABreadth, ADistance: Integer): Integer;
- procedure PGMakeLabelsWordWrap;
-
- function PGFullFilename(AFilename: string): string;
-
- implementation
-
- {$R *.DFM}
-
- { Include a resource file that has some icons in it. This is used }
- { to demonstrate how you can use the Animated TrayIcon VCL with icons }
- { that reside in the current executable. See the "SamplesComboBoxChange" }
- { method for some sample code. }
- {$IFDEF WIN32}
- {$R ICONS32.RES}
- {$ELSE}
- {$R ICONS16.RES}
- {$ENDIF}
-
- procedure PGAssert(const Condition: Boolean; const Msg: string);
- begin
- if Condition then
- exit;
-
- PGError(Msg);
- Halt;
- end;
-
- procedure PGError(const Msg: string);
- begin
- ShowMessage(Msg);
- end;
-
- function PGMin(X, Y: Integer): Integer;
- begin
- Result := X;
- if Y < X then Result := Y;
- end;
-
- function PGMax(X, Y: Integer): Integer;
- begin
- Result := X;
- if Y > X then Result := Y;
- end;
-
- function PGCenter(ABreadth, ADistance: Integer): Integer;
- begin
- Result := (ADistance - ABreadth) div 2;
- end;
-
-
- { Shows or hides an object, depending on which way the demo is 'playing' }
- procedure TMainForm.ShowObject(AnObjectName: string);
- var
- AControl: TControl;
- begin
- AControl := nil;
-
- AControl := TControl(FindComponent(AnObjectName));
- if (AControl <> nil) then
- AControl.Visible := PlayingForward;
- end;
-
- { Given an object's name, look's for the object on the main form. If it is }
- { found, the function returns true, and the AControl variable is updated to }
- { point to the control we were looking for. }
- function TMainForm.PageObject(AnObjectName: string): TControl;
- var
- APageObjectName: string;
- begin
- Result := nil;
- APageObjectName := PageObjectName(AnObjectName);
- Result := TControl(FindComponent(APageObjectName));
- PGAssert((Result <> nil), 'Object doesnt exist:' + APageObjectName);
- end;
-
- function TMainForm.StepObject(AnObjectName: string; AStep: Integer): TControl;
- var
- APageObjectName: string;
- begin
- APageObjectName := AnObjectName + IntToStr(AStep);
- Result := PageObject(APageObjectName);
- end;
-
- function TMainForm.PageObjectName(AName: string): string;
- begin
- Result := Format('Page%d%s', [CurrPage, AName]);
- end;
-
- { Shows or hides a bullet and another object, depending on the }
- { direction we're 'playing'. }
- procedure TMainForm.ShowBullet(AnObjectName: string);
- var
- Bullet: TControl;
- BulletLeft: Integer;
- BulletTop: Integer;
- ObjectToBullet: TControl;
- begin
- { Figure out where to display the bullet. }
- Bullet := PageObject('Bullet');
- ObjectToBullet := PageObject(AnObjectName);
-
- BulletLeft := ObjectToBullet.Left - Bullet.Width - 3;
- BulletTop := ObjectToBullet.Top + 4;
- Bullet.Left := BulletLeft;
- Bullet.Top := BulletTop;
-
- { Show the bullet and the object. }
- Bullet.Visible := PlayingForward;
- ObjectToBullet.Visible := PlayingForward;
- end;
-
- procedure TMainForm.ShowBulletedLabel(AStep: Integer);
- begin
- ShowBullet('Label' + IntToStr(AStep));
- end;
-
- { Used to force examples to hide between pages, and to ensure that bullets }
- { are always initially hidden. }
- procedure TMainForm.InitNewStep;
- begin
- if not GoingForward then
- exit;
-
- PageObject('Bullet').Visible := false;
- end;
-
- { Enable, Disable, and Modify the navigation buttons depending on where we }
- { are in the demo's content. }
- procedure TMainForm.UpdateNavigationState;
- begin
- { At the first page ... }
- if (CurrPage = FirstPage) and (CurrStep = FirstStep) then
- begin
- BackButton.Enabled := false;
- NextButton.Enabled := true;
- exit;
- end;
-
- { At the last page ... }
- if (CurrPage = LastPage) and (CurrStep = NumberOfStepsInPage(CurrPage)) then
- begin
- BackButton.Enabled := true;
- NextButton.Enabled := false;
- exit;
- end;
-
- { At some page inbetween ... }
- BackButton.Enabled := true;
- NextButton.Enabled := true;
- end;
-
- procedure TMainForm.DisplayPage(APageIndex: Integer);
- begin
- { Display the new page. }
- Pages.PageIndex := APageIndex - 1;
-
- { Show the new pages title in the current page title bar. }
- CurrentPage.Caption := Pages.ActivePage;
- end;
-
- procedure TMainForm.DisplayNextPage;
- begin
- if CurrPage = LastPage then
- exit;
-
- { Display the new page. }
- Pages.PageIndex := Pages.PageIndex + 1;
-
- { Show the new pages title in the current page title bar. }
- CurrentPage.Caption := Pages.ActivePage;
-
- CurrStep := 0;
- GoForward;
- end;
-
- procedure TMainForm.DisplayPrevPage;
- begin
- if CurrPage = FirstPage then
- exit;
-
- Pages.PageIndex := Pages.PageIndex - 1;
- InitEndOfPage(CurrPage);
-
- { Show the new pages title in the current page title bar. }
- CurrentPage.Caption := Pages.ActivePage;
- end;
-
- function TMainForm.FirstPage: Integer;
- begin
- Result := 1;
- end;
-
- function TMainForm.LastPage: Integer;
- begin
- Result := Pages.Pages.Count;
- end;
-
- function TMainForm.CurrPage: Integer;
- begin
- Result := Pages.PageIndex + 1;
- end;
-
- function TMainForm.GoForward: Boolean;
- var
- LastStep: Integer;
- begin
- { Go to the next step. }
- GoingForward := true;
- PlayingForward := true;
-
- LastStep := CurrStep;
- CurrStep := NextStep;
-
- { If we're at a different step, then display it. }
- Result := (CurrStep <> LastStep);
- if Result then
- DisplayStep(CurrStep);
- UpdateNavigationState;
- end;
-
- function TMainForm.FirstStep: Integer;
- begin
- Result := 1;
- end;
-
- function TMainForm.LastStep: Integer;
- begin
- Result := 20;
- end;
-
- function TMainForm.GoBackward: Boolean;
- var
- LastStep: Integer;
- begin
- { Go to the prev step. }
- GoingForward := false;
- PlayingForward := false;
- DisplayStep(CurrStep);
-
- if (CurrStep = FirstStep) then
- begin
- DisplayPrevPage;
- exit;
- end;
-
- { If we're at a different step, then display it. }
- Result := (CurrStep <> LastStep);
- LastStep := CurrStep;
- CurrStep := PrevStep;
-
- PlayingForward := true;
- if Result then
- DisplayStep(CurrStep);
- UpdateNavigationState;
- end;
-
- function TMainForm.NextStep: Integer;
- begin
- Result := PGMin(CurrStep + 1, LastStep);
- end;
-
- function TMainForm.PrevStep: Integer;
- begin
- Result := PGMax(CurrStep - 1, FirstStep);
- end;
-
- procedure TMainForm.DisplayHintInStatusBar(Sender: TObject);
- begin
- UpdateStatusBar(Application.Hint);
- end;
-
- procedure TMainForm.FormCreate(Sender: TObject);
- begin
- { Change to the project directory so the help file will be available. }
- ChangeDirectory(ExtractFilePath(Application.Exename));
-
- { Show the components help if the user needs help. }
- Application.HelpFile := PGFullFilename('PGTRAY95.HLP');
-
- { Initialize showing hints in the status bar. }
- Application.OnHint := DisplayHintInStatusBar;
- UpdateStatusBar(EmptyStr);
-
- { Initially display the "Smiley Face" sample when the Demo begins. }
- SamplesComboBox.ItemIndex := 0;
- SamplesComboBoxChange(Self);
-
- { Load hand cursors into hot spot labels. }
- MakeHotSpotLabel(Page4Label5b);
- MakeHotSpotLabel(Page4Label1b);
- MakeHotSpotLabel(Page5Label1a);
- MakeHotSpotLabel(Page5Label2a);
-
- { Show the Introduction page of the demo. }
- Pages.ActivePage := 'Introduction';
- CurrStep := 0;
- GoForward;
-
- { Display a dialog that explains what the Demo demonstrates. }
- TrayIcon.HideApplication;
- TrayIcon.PostEvent(ShowDemoDialog);
- end;
-
- procedure TMainForm.NextButtonClick(Sender: TObject);
- begin
- GoForward;
- end;
-
- procedure TMainForm.BackButtonClick(Sender: TObject);
- begin
- GoBackward;
- end;
-
- { In Delphi 1.0, If you try and "ChDir" to a directory that was }
- { extracted from a filename with "ExtractFilePath", you will get an error }
- { because "ChDir" doesn't like trailing slashes, and "ExtractFilePath" }
- { leaves trailing slashes on. This removes the trailing slash. This }
- { problem only occurs under Windows 95. }
- procedure TMainForm.ChangeDirectory(APath: string);
- var
- LastCharPos: Integer;
- begin
- { Remove the trailing slash if it exists. }
- LastCharPos := Length(APath);
- if APath[LastCharPos] = '\' then
- Delete(APath, LastCharPos, 1);
-
- { Change to the destination directory. }
- ChDir(APath);
- end;
-
- procedure TMainForm.UpdateStatusBar(StatusText: string);
- begin
- if StatusBar.Caption = StatusText then
- exit;
- StatusBar.Caption := ' ' + StatusText;
- end;
-
- procedure TMainForm.CurrentPageMouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- begin
- UpdateStatusBar(EmptyStr)
- end;
-
- { Returns a fully qualified filename for files in the demo directory. }
- function PGFullFilename(AFilename: string): string;
- begin
- Result := ExtractFilePath(Application.Exename) + AFilename;
- end;
-
- procedure TMainForm.Button1Click(Sender: TObject);
- begin
- Application.Terminate;
- end;
-
- procedure TMainForm.InitEndOfPage(APageIndex: Integer);
- begin
- CurrStep := NumberOfStepsInPage(APageIndex);
- case APageIndex of
- 2: ;
- end;
- end;
-
- { Use the MessageBox API call to show our messages to make sure that }
- { they are always shown "On Top", regardless of which application currently }
- { has the focus. }
- procedure TMainForm.ShowMsg(AMsg: string);
- var
- APCharMsg: array[0..255] of char;
- begin
- StrPCopy(APCharMsg, AMsg);
- {$IFDEF WIN32}
- MessageBox(Application.Handle, APCharMsg, 'Animated TrayIcon VCL', mb_OK + mb_SetForeground + mb_IconInformation);
- {$ELSE}
- MessageBox(Application.Handle, APCharMsg, 'Animated TrayIcon VCL', mb_OK + mb_IconInformation);
- {$ENDIF}
- end;
-
- procedure TMainForm.ShowAbout;
- var
- AMsg: string;
- begin
- AMsg := 'Animated TrayIcon VCL v3.0' + #13#13 + 'by The Programmers' + #39 + ' Guild';
- MainForm.ShowMsg(AMsg);
- end;
-
- procedure TMainForm.AbouttheProgrammersGuild1Click(Sender: TObject);
- begin
- ShowAbout;
- end;
-
- procedure TMainForm.HowtoRegister1Click(Sender: TObject);
- begin
- Application.HelpContext(11);
- end;
-
- { URL Label - See Credits at beginning of unit. }
- procedure TMainForm.URLLabelClick(Sender: TObject);
- var
- AnUrl: array[0..255] of char;
- begin
- StrPCopy(AnUrl, 'http://www.programmersguild.com/');
- ShellExecute(Application.Handle, 'open', AnUrl, nil, nil, SW_NORMAL);
- end;
-
- { URL Label - See Credits at beginning of unit. }
- procedure TMainForm.URLCopyMenuItemClick(Sender: TObject);
- var
- AnURLLabel: TLabel;
- begin
- AnURLLabel := TLabel(URLPopupMenu.PopupComponent);
- Clipboard.AsText := AnURLLabel.Caption;
- end;
-
- { URL Label - See Credits at beginning of unit. }
- procedure TMainForm.MakeHotSpotLabel(ALabel: TLabel);
- begin
- Screen.Cursors[crPGURLHand] := LoadCursor(HInstance, PChar('TPGTRAYICON95HAND'));
- ALabel.Cursor := crPGURLHand;
- end;
-
- procedure TMainForm.Page4Label5bMouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- begin
- UpdateStatusBar('View detailed registration information.');
- end;
-
- procedure TMainForm.Page5Label2aMouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- begin
- UpdateStatusBar('Go to The Programmers' + #39 + ' Guild Home Page.');
- end;
-
- procedure TMainForm.Page4Label1bMouseMove(Sender: TObject; Shift: TShiftState;
- X, Y: Integer);
- begin
- UpdateStatusBar('Go to our online registration service.');
- end;
-
- procedure TMainForm.Page4Label1bClick(Sender: TObject);
- var
- AnUrl: array[0..255] of char;
- begin
- StrPCopy(AnUrl, 'http://www.programmersguild.com/');
- ShellExecute(Application.Handle, 'open', AnUrl, nil, nil, SW_NORMAL);
- end;
-
- procedure TMainForm.ShowIconButtonClick(Sender: TObject);
- begin
- { Show the TrayIcon in the system tray. }
- TrayIcon.ShowIcon;
- end;
-
- procedure TMainForm.HideIconButtonClick(Sender: TObject);
- begin
- { Hide the TrayIcon. }
- TrayIcon.HideIcon;
- end;
-
- procedure TMainForm.AnimatedLabelClick(Sender: TObject);
- begin
- { Animates the TrayIcon if it is not already being animated. }
- if not AnimatedRadioButton.Checked then
- AnimatedRadioButton.Checked := true;
- end;
-
- procedure TMainForm.EnabledLabelClick(Sender: TObject);
- begin
- { Enables the TrayIcon if it is not already enabled. }
- if not EnabledRadioButton.Checked then
- EnabledRadioButton.Checked := true;
- end;
-
- procedure TMainForm.DisabledLabelClick(Sender: TObject);
- begin
- { Disables the TrayIcon if it is not already disabled. }
- if not DisabledRadioButton.Checked then
- DisabledRadioButton.Checked := true;
- end;
-
- procedure TMainForm.AnimatedRadioButtonClick(Sender: TObject);
- begin
- { Tell the TrayIcon to display the icons that are listed in }
- { the Animation.Icons property. }
- TrayIcon.State := tsAnimated;
- end;
-
- procedure TMainForm.EnabledRadioButtonClick(Sender: TObject);
- begin
- { Tell the TrayIcon to display the icon in it's "Icon" property. }
- TrayIcon.State := tsEnabled;
- end;
-
- procedure TMainForm.DisabledRadioButtonClick(Sender: TObject);
- begin
- { Tell the TrayIcon to display the icon in it's "DisabledIcon" property. }
- TrayIcon.State := tsDisabled;
- end;
-
- procedure TMainForm.AutoPopupLabelClick(Sender: TObject);
- begin
- { Toggles displaying the right click Popup menu on and off. }
- AutoPopupCheckBox.Checked := not AutoPopupCheckBox.Checked;
- end;
-
- procedure TMainForm.ShowHintLabelClick(Sender: TObject);
- begin
- { Toggles displaying the icon's hint on and off. }
- ShowHintCheckBox.Checked := not ShowHintCheckBox.Checked;
- end;
-
- procedure TMainForm.AutoPopupCheckboxClick(Sender: TObject);
- begin
- { Toggles displaying the Popup menu on right click on/off. }
- TrayIcon.AutoPopup := AutoPopupCheckBox.Checked;
- end;
-
- procedure TMainForm.ShowHintCheckboxClick(Sender: TObject);
- begin
- { Toggles displaying the icon's hint on/off. }
- TrayIcon.ShowHint := ShowHintCheckBox.Checked;
- end;
-
- procedure TMainForm.HintEditChange(Sender: TObject);
- begin
- { Display the hint that the user just typed in. }
- TrayIcon.Hint := HintEdit.Text;
- end;
-
- procedure TMainForm.TrayIconClick(Sender: TObject);
- var
- AMsg: string;
- begin
- { Figure out which mouse button was clicked. }
- case TrayIcon.ClickedMouseButton of
- mbLeft: AMsg := 'Left Single Click !!!';
- mbMiddle: AMsg := 'Middle Single Click !!!';
- mbRight: AMsg := 'Right Single Click !!!';
- end;
-
- { Respond to the icon begin double clicked. }
- ShowMsg(AMsg);
- end;
-
- procedure TMainForm.TrayIconDblClick(Sender: TObject);
- var
- AMsg: string;
- begin
- { Figure out which mouse button was double clicked. }
- case TrayIcon.ClickedMouseButton of
- mbLeft: AMsg := 'Left Double Click !!!';
- mbMiddle: AMsg := 'Middle Double Click !!!';
- mbRight: AMsg := 'Right Double Click !!!';
- end;
-
- { Respond to the icon begin double clicked. }
- ShowMsg(AMsg);
- end;
-
- procedure TMainForm.SamplesComboBoxChange(Sender: TObject);
- begin
- { Make sure that we're in the application directory, so }
- { we can find the sample icons. }
- ChangeDirectory(ExtractFilePath(Application.Exename));
-
- { Load the group of icons that the user selected. }
- { i.e. Make the TrayIcon display: }
- { 1. A Smiley Face. }
- { 2. A Burning Trashcan. }
- { 3. A Flashing light bulb. }
- case SamplesComboBox.ItemIndex of
-
- 0: { Smiley Face !!! }
- begin
- { Set the icons that will be displayed when the }
- { TrayIcon is in its enabled and disabled states. }
- TrayIcon.Icon.LoadFromFile('SMILEY3.ICO');
- TrayIcon.DisabledIcon.LoadFromFile('SAD.ICO');
-
- { Tell the TrayIcon that the icons to be used in the }
- { animation are icon files. }
- TrayIcon.Animation.Options := aoIconsAreFiles;
- TrayIcon.Animation.Icons.Clear;
- TrayIcon.Animation.Icons.Add('SMILEY1.ICO');
- TrayIcon.Animation.Icons.Add('SMILEY2.ICO');
- TrayIcon.Animation.Icons.Add('SMILEY3.ICO');
- TrayIcon.Animation.Icons.Add('SMILEY4.ICO');
- TrayIcon.Animation.Icons.Add('SMILEY3.ICO');
-
- { Make the animation of the face smiling and winking a "slow" }
- { animation so we can see the expressions clearly. }
- TrayIcon.Animation.Interval := 400;
- end;
-
- 1: { Flashing Light }
- { Note: The following code sets up the TrayIcon to use icons }
- { that were included as resources in the current executable. }
- { This allows developers to create TrayIcon applications that will }
- { not require external icon files at runtime. }
- begin
- { Set the icons that will be displayed when the }
- { TrayIcon is in its enabled and disabled states. }
- { In the above example, these icons were loaded from }
- { external icon files. In this example, the icons are }
- { included in the executable, so we load the icons by }
- { using the LoadIcon API call. }
- TrayIcon.Icon.Handle := WinProcs.LoadIcon(HInstance, 'LIGHTON');
- TrayIcon.DisabledIcon.Handle := WinProcs.LoadIcon(HInstance, 'LIGHTOFF');
-
- { Tell the TrayIcon that the icons to be used in the }
- { animation are icon resources that are included in }
- { the current executable. While the above Icon and DisabledIcon }
- { properties required us to use the LoadIcon API call to load }
- { an icon from the executable, the Animation property takes care }
- { of these details "behind the scenes", once it is has been }
- { told where to look. }
- TrayIcon.Animation.Options := aoIconsInExe;
- TrayIcon.Animation.Icons.Clear;
- TrayIcon.Animation.Icons.Add('LIGHTON');
- TrayIcon.Animation.Icons.Add('LIGHTON');
- TrayIcon.Animation.Icons.Add('LIGHTOFF');
- TrayIcon.Animation.Icons.Add('LIGHTOFF');
- TrayIcon.Animation.Icons.Add('LIGHTON');
- TrayIcon.Animation.Icons.Add('LIGHTOFF');
- TrayIcon.Animation.Icons.Add('LIGHTON');
- TrayIcon.Animation.Icons.Add('LIGHTOFF');
-
- { Make the animation of the light bulb flashing on and off }
- { a "fast" animation. }
- TrayIcon.Animation.Interval := 150;
- end;
-
- 2: { Burning Trashcan }
- begin
- { Set the icons that will be displayed when the }
- { TrayIcon is in its enabled and disabled states. }
- TrayIcon.Icon.LoadFromFile('TRASH3.ICO');
- TrayIcon.DisabledIcon.LoadFromFile('NOTRASH.ICO');
-
- { Tell the TrayIcon that the icons to be used in the }
- { animation are icon files. }
- TrayIcon.Animation.Options := aoIconsAreFiles;
- TrayIcon.Animation.Icons.Clear;
- TrayIcon.Animation.Icons.Add('TRASH1.ICO');
- TrayIcon.Animation.Icons.Add('TRASH2.ICO');
- TrayIcon.Animation.Icons.Add('TRASH3.ICO');
-
- { Make the animation of the fire burning in the trashcan }
- { a "fast" animation to simulate the flickering of a fire. }
- TrayIcon.Animation.Interval := 150;
- end;
- end;
-
- { Display the icons for this sample on the form. }
- EnabledIconImage.Picture.Bitmap.Handle := 0;
- DisabledIconImage.Picture.Bitmap.Handle := 0;
- EnabledIconImage.Picture.Icon.Assign(TrayIcon.Icon);
- DisabledIconImage.Picture.Icon.Assign(TrayIcon.DisabledIcon);
-
- { Set the hint of the TrayIcon to display the name of the }
- { current sample being displayed. }
- TrayIcon.Hint := SamplesComboBox.Text;
- end;
-
- procedure TMainForm.EnabledIconImageDblClick(Sender: TObject);
- begin
- { Change the enabled icon to the icon that the user }
- { selected in the browse dialog. }
- if BrowseForIconDialog.Execute then
- begin
- TrayIcon.Icon.LoadFromFile(BrowseForIconDialog.Filename);
- EnabledIconImage.Picture.Bitmap.Handle := 0;
- EnabledIconImage.Picture.LoadFromFile(BrowseForIconDialog.Filename);
- EnabledRadioButton.Checked := true;
- end;
- end;
-
- procedure TMainForm.DisabledIconImageDblClick(Sender: TObject);
- begin
- { Change the disabled icon to the icon that the user }
- { selected in the browse dialog. }
- if BrowseForIconDialog.Execute then
- begin
- TrayIcon.DisabledIcon.LoadFromFile(BrowseForIconDialog.Filename);
- DisabledIconImage.Picture.Bitmap.Handle := 0;
- DisabledIconImage.Picture.LoadFromFile(BrowseForIconDialog.Filename);
- DisabledRadioButton.Checked := true;
- end;
- end;
-
- procedure TMainForm.TrayIconMouseEnter(Sender: TObject; Shift: TShiftState;
- X, Y: Integer);
- begin
- ShowTrackingMessage('Entering TrayIcon', X, Y);
- end;
-
- procedure TMainForm.TrayIconMouseMove(Sender: TObject; Shift: TShiftState;
- X, Y: Integer);
- begin
- ShowTrackingMessage(' Moving over TrayIcon', X, Y);
- end;
-
- procedure TMainForm.TrayIconMouseExit(Sender: TObject; Shift: TShiftState;
- X, Y: Integer);
- begin
- ShowTrackingMessage(' Leaving TrayIcon', X, Y);
- end;
-
- function PGInStr(TargetString, SubString: string): Boolean;
- begin
- Result := Pos(SubString, TargetString) <> 0;
- end;
-
- procedure TMainForm.ShowTrackingMessage(AString: string; X,Y: Integer);
- var
- LastItem: string;
- LastItemIndex: Integer;
- NewItem: string;
- begin
- { Figure out the new item string. }
- NewItem := Format('%s at (%d,%d)', [AString, X, Y]);
-
- { Figure out where the new item should go. If its a moving message and }
- { a moving message was the last message in the list box, update it, }
- { otherwise just tag it onto the end of the list. }
- LastItemIndex := TrackingListBox.Items.Count - 1;
- if LastItemIndex >= 0 then
- begin
- LastItem := TrackingListBox.Items[LastItemIndex];
- if PGInStr(LastItem, 'Moving') and PGInStr(AString, 'Moving') then
- TrackingListBox.Items[LastItemIndex] := NewItem
- else
- TrackingListBox.Items.Add(NewItem);
- end
- else
- TrackingListBox.Items.Add(NewItem);
-
- { Make sure that the last item in the list box is always selected, so }
- { users can see the additions as they happen. }
- TrackingListBox.ItemIndex := TrackingListBox.Items.Count - 1;
- end;
-
- procedure TMainForm.Button2Click(Sender: TObject);
- begin
- TrackingListBox.Clear;
- end;
-
- procedure TMainForm.ShowDemoDialog(Sender: TObject);
- var
- MsgStr: string;
- begin
- MsgStr := EmptyStr;
- MsgStr := MsgStr + 'This application demonstrates key features' + #10;
- MsgStr := MsgStr + 'of the Animated TrayIcon VCL.' + #10#10;
- MsgStr := MsgStr + 'Click OK, and right click the "Smiley Face"' + #10;
- MsgStr := MsgStr + 'TrayIcon to display a Popup menu and' + #10;
- MsgStr := MsgStr + 'further explore the components features.' + #10;
-
- { Display the introductory dialog. }
- ShowMsg(MsgStr);
- end;
- procedure TMainForm.ShowDemo1Click(Sender: TObject);
- begin
- { Shows the application by showing both the Main Form and }
- { the Application's task bar icon. }
- TrayIcon.ShowApplication;
- end;
-
- procedure TMainForm.HideDemo1Click(Sender: TObject);
- begin
- { Hide's the application by hiding both the Main Form and }
- { the Application's task bar icon. }
- TrayIcon.HideApplication;
- end;
-
- procedure TMainForm.Registration1Click(Sender: TObject);
- begin
- { Display the Registration help topic in the component help file. }
- Application.HelpJump('Ordering_Information_Order_Form');
- end;
-
- procedure TMainForm.About1Click(Sender: TObject);
- begin
- ShowAbout;
- exit;
- { Display the About information for this component. }
- Application.HelpJump('About');
- end;
-
- procedure TMainForm.Exit2Click(Sender: TObject);
- begin
- { Exit the Demo. }
- Application.Terminate;
- end;
-
- procedure TMainForm.DisplayStep(AStep: Integer);
- begin
- InitNewStep;
- case CurrPage of
- 1: { Page 1 }
- case AStep of
- 1: ShowBulletedLabel(1);
- 2: ShowBulletedLabel(2);
- 3: ShowBulletedLabel(3);
- 4: ShowBulletedLabel(4);
- 5: ShowBulletedLabel(5);
- 6: ShowBulletedLabel(6);
- 7: ShowBulletedLabel(7);
- 8: ShowObject('Page1Label8');
- 9: DisplayNextPage;
- end;
-
- 2: { Page 2 }
- case AStep of
- 1: begin
- ShowBullet('Image1');
- ShowObject('Page2Label1');
- end;
- 2: begin
- ShowBulletedLabel(2);
- ShowObject('SamplesComboBox');
- end;
- 3: begin
- ShowBulletedLabel(3);
- ShowObject('AnimatedRadioButton');
- ShowObject('AnimatedLabel');
- ShowObject('EnabledRadioButton');
- ShowObject('EnabledLabel');
- ShowObject('EnabledIconImage');
- ShowObject('DisabledRadioButton');
- ShowObject('DisabledLabel');
- ShowObject('DisabledIconImage');
- end;
- 4: begin
- ShowBulletedLabel(4);
- ShowObject('ShowIconButton');
- ShowObject('HideIconButton');
- end;
- 5: begin
- ShowBulletedLabel(5);
- ShowObject('ShowHintLabel');
- ShowObject('ShowHintCheckBox');
- ShowObject('AutoPopupLabel');
- ShowObject('AutoPopupCheckBox');
- ShowObject('HintLabel');
- ShowObject('HintEdit');
- end;
- 6: begin
- TrackingListBox.Clear;
- DisplayNextPage;
- end;
- end;
-
- 3: { Page 3 }
- case AStep of
- 1: ShowBulletedLabel(1);
- 2: DisplayNextPage;
- end;
-
- 4: { Page 4 }
- case AStep of
- 1: begin
- ShowObject('Page4Label1');
- ShowObject('Page4Label1b');
- ShowBullet('Image1');
- end;
- 2: begin
- ShowObject('Page4Label2');
- ShowBullet('Image2');
- end;
- 3: begin
- ShowObject('Page4Label3');
- ShowBullet('Image3');
- end;
- 4: ShowBulletedLabel(4);
- 5: begin
- ShowObject('Page4Label5a');
- ShowObject('Page4Label5b');
- ShowObject('Page4Label5c');
- end;
- 6: DisplayNextPage;
- end;
-
- 5: { Page 5 }
- case AStep of
- 1: begin
- ShowBulletedLabel(1);
- ShowObject('Page5Label1a');
- end;
- 2: begin
- ShowBulletedLabel(2);
- ShowObject('Page5Label2a');
- end;
- 3: begin
- ShowBulletedLabel(3);
- ShowObject('Page5Label3A');
- ShowObject('Page5Label3B');
- ShowObject('Page5Label3C');
- ShowObject('Page5Label3D');
- end;
- 4: DisplayNextPage;
- end;
- end;
- end;
-
- function TMainForm.NumberOfStepsInPage(APageIndex: Integer): Integer;
- begin
- case APageIndex of
- 1: Result := 8;
- 2: Result := 5;
- 3: Result := 1;
- 4: Result := 5;
- 5: Result := 3;
- else
- Result := FirstStep;
- end;
- end;
-
- procedure TMainForm.Page5Label1aClick(Sender: TObject);
- var
- AnUrl: array[0..255] of char;
- begin
- StrPCopy(AnUrl, 'mailto: feedback@programmersguild.com');
- ShellExecute(Application.Handle, 'open', AnUrl, nil, nil, SW_NORMAL);
- end;
-
- procedure TMainForm.Page5Label1aMouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- begin
- UpdateStatusBar('Contact The Programmers' + #39 + ' Guild via E-mail.');
- end;
-
- procedure TMainForm.TrayIconAppMinimize(Sender: TObject);
- begin
- { Make sure that if someone minimizes the Demo they have a }
- { way of showing the Demo again - ie Make sure they haven't }
- { turned off the TrayIcon's PopupMenu, which allows them to }
- { show the demo when it's minimized in the System Tray. }
- if not AutoPopupCheckBox.Checked then
- AutoPopupCheckBox.Checked := true;
- end;
-
- procedure TMainForm.FormShow(Sender: TObject);
- begin
- PGMakeLabelsWordWrap;
- end;
-
- procedure PGMakeLabelsWordWrap;
- var
- AFormCount: Integer;
- AComponentCount: Integer;
- i: Integer;
- j: Integer;
- ALabel: TLabel;
- AForm: TForm;
- begin
- AFormCount := Screen.FormCount;
-
- for i := 0 to AFormCount - 1 do
- begin
- AForm := Screen.Forms[i];
- AComponentCount := AForm.ComponentCount;
- for j := 0 to AComponentCount - 1 do
- begin
- if AForm.Components[j] is TLabel then
- begin
- ALabel := TLabel(AForm.Components[j]);
- ALabel.WordWrap := true;
- end;
- end;
- end;
- end;
-
- end.
-